package  
{
	import flash.text.TextField;
	/**
	 * ...
	 * @author patsup
	 * 
	 * 		This class handles the functionality for the menu prior to the start of every round
	 * 	(before the "PGame" begins/continues).
	 * 		The buttons are of the generalized class MenuButton.
	 * 
	 * 		AchievBtnInputMouseClick() takes you to another "menu"
	 * 		ViewPayoutBtnInputMouseClick() just pops up the payout table as another "big button"
	 * 
	 * *** protected functions
	 * 
	 * PlayBtnInputMouseClick():void
	 * MenuBtnInputMouseClick():void
	 * IncBetBtnInputMouseClick():void
	 * DecBetBtnInputMouseClick():void
	 * AchievBtnInputMouseClick():void
	 * ViewPayoutBtnInputMouseClick():void
	 * PayoutDisplayInputMouseClick():void
	 * 
	 */
	public class PreRoundMenu extends Menu 
	{
		//preround menu image parameters
		private const COLOR:int = 0x8080FF;
		private const WIDTH:int = 640;
		private const HEIGHT:int = 480;
		//buttons
		private const PLAY_BUTTON_X_STARTLOC:int = 420;			//Button for Play Round
		private const PLAY_BUTTON_Y_STARTLOC:int = 400;
		private const P_BTN_COLOR:int = 0xFF8000;
		private const P_BTN_WIDTH:int = 120;
		private const P_BTN_HEIGHT:int = 40;
		private const MENU_BUTTON_X_STARTLOC:int = 550;			//Button for return Back to menu
		private const MENU_BUTTON_Y_STARTLOC:int = 390;
		private const M_BTN_COLOR:int = 0xC0C0C0;
		private const M_BTN_WIDTH:int = 45;
		private const M_BTN_HEIGHT:int = 60;
		private const INCR_BET_BUTTON_X_STARTLOC:int = 560;		//Button for Increase Bet
		private const INCR_BET_BUTTON_Y_STARTLOC:int = 80;
		private const I_BTN_COLOR:int = 0xFF8000;
		private const I_BTN_WIDTH:int = 60;
		private const I_BTN_HEIGHT:int = 40;
		private const DECR_BET_BUTTON_X_STARTLOC:int = 400;		//Button for Decrease Bet
		private const DECR_BET_BUTTON_Y_STARTLOC:int = 80;
		private const D_BTN_COLOR:int = 0xFF8000;
		private const D_BTN_WIDTH:int = 60;
		private const D_BTN_HEIGHT:int = 40;
		private const ACHIEV_BUTTON_X_STARTLOC:int = 370;		//Button for Achievements menu
		private const ACHIEV_BUTTON_Y_STARTLOC:int = 300;
		private const A_BTN_COLOR:int = 0x0080FF;
		private const A_BTN_WIDTH:int = 220;
		private const A_BTN_HEIGHT:int = 60;
		private const PAYOUT_BTN_X:int = 340;					//Button for view payout
		private const PAYOUT_BTN_Y:int = 380;
		private const PO_BTN_COLOR:int = 0xFFFF80;
		private const PO_BTN_WIDTH:int = 60;
		private const PO_BTN_HEIGHT:int = 80;
		private const PAYOUT_DISP_X:int = 1;					//Payout Display
		private const PAYOUT_DISP_Y:int = 1;
		private const PO_DSP_COLOR:int = 0xFFFF00;
		private const PO_DSP_WIDTH:int = 638;
		private const PO_DSP_HEIGHT:int = 478;
		private const PO_DSP_ALPHA:Number = 0.8;
		//text fields
		private const BET_TXT_X_STARTLOC:int = 480;					//Text for Current Bet Size
		private const BET_TXT_Y_STARTLOC:int = 80;
		private const MONEY_TXT_X_STARTLOC:int = 480;				//Text for Total Money
		private const MONEY_TXT_Y_STARTLOC:int = 30;
		
		//button image data
		private var playButtonImgData:ImageData;
		private var menuButtonImgData:ImageData;
		private var incrBetButtonImgData:ImageData;
		private var decrBetButtonImgData:ImageData;
		private var achievButtonImgData:ImageData;
		private var viewPayoutButtonImgData:ImageData;
		private var payoutDisplayImgData:ImageData;
		
		//buttons
		private var playButton:MenuButton;
		private var menuButton:MenuButton;						//return to start menu button
		private var incrBetButton:MenuButton;
		private var decrBetButton:MenuButton;
		private var achievButton:MenuButton;
		private var viewPayoutButton:MenuButton;
		private var payoutDisplay:MenuButton;
		
		//text fields
		private var currentBetText:TextField;
		private var totalMoneyText:TextField;
		
		private var txtLabel:TextField;
		
		private var mainRef:Main;
		private var gameRef:PGame;
		
		public function PreRoundMenu(mainRef:Main, gameRef:PGame) 
		{
			txtLabel = new TextField();
			this.mainRef = mainRef;
			this.gameRef = gameRef;
			
			InitImage();
			
		}
		
		//InitImage()
		//Initializes the image of the Menu
		protected override function InitImage():void
		{
			//background
			graphics.beginFill(COLOR);
			graphics.drawRect(0, 0, WIDTH, HEIGHT);
			graphics.endFill();
			
			txtLabel.text = "Pre Round Menu";
			addChild(txtLabel);
			
			//button image data
			playButtonImgData = new ImageData(PLAY_BUTTON_X_STARTLOC, PLAY_BUTTON_Y_STARTLOC, "Play");
			menuButtonImgData = new ImageData(MENU_BUTTON_X_STARTLOC, MENU_BUTTON_Y_STARTLOC, "Back", M_BTN_COLOR, M_BTN_WIDTH, M_BTN_HEIGHT);
			incrBetButtonImgData = new ImageData(INCR_BET_BUTTON_X_STARTLOC, INCR_BET_BUTTON_Y_STARTLOC, "+ + +", I_BTN_COLOR, I_BTN_WIDTH, I_BTN_HEIGHT, 1, "Ellipse");
			decrBetButtonImgData = new ImageData(DECR_BET_BUTTON_X_STARTLOC, DECR_BET_BUTTON_Y_STARTLOC, "- - -", D_BTN_COLOR, D_BTN_WIDTH, D_BTN_HEIGHT, 1, "Ellipse");
			achievButtonImgData = new ImageData(ACHIEV_BUTTON_X_STARTLOC, ACHIEV_BUTTON_Y_STARTLOC, "Achievements", A_BTN_COLOR, A_BTN_WIDTH, A_BTN_HEIGHT, 1, "Ellipse");
			viewPayoutButtonImgData = new ImageData(PAYOUT_BTN_X, PAYOUT_BTN_Y, "View\nPayouts", PO_BTN_COLOR, PO_BTN_WIDTH, PO_BTN_HEIGHT, 1, "Ellipse");
			var _payoutTable:String = gameRef.GetSS().GetPayoutTable();
			payoutDisplayImgData = new ImageData(PAYOUT_DISP_X, PAYOUT_DISP_Y, _payoutTable, PO_DSP_COLOR, PO_DSP_WIDTH, PO_DSP_HEIGHT, PO_DSP_ALPHA);
			
			//buttons
			playButton = new MenuButton(playButtonImgData, PlayBtnInputMouseClick);
			menuButton = new MenuButton(menuButtonImgData, MenuBtnInputMouseClick);
			incrBetButton = new MenuButton(incrBetButtonImgData, IncBetBtnInputMouseClick);
			decrBetButton = new MenuButton(decrBetButtonImgData, DecBetBtnInputMouseClick);
			achievButton = new MenuButton(achievButtonImgData, AchievBtnInputMouseClick);
			viewPayoutButton = new MenuButton(viewPayoutButtonImgData, ViewPayoutBtnInputMouseClick);
			payoutDisplay = new MenuButton(payoutDisplayImgData, PayoutDisplayInputMouseClick);
			
			//text fields
			currentBetText = new TextField();
			currentBetText.text = gameRef.GetSS().GetCurrentBetSize().toString();
			currentBetText.x = BET_TXT_X_STARTLOC;
			currentBetText.y = BET_TXT_Y_STARTLOC;
			totalMoneyText = new TextField();
			totalMoneyText.text = gameRef.GetSS().GetTotalMoney().toString();
			totalMoneyText.x = MONEY_TXT_X_STARTLOC;
			totalMoneyText.y = MONEY_TXT_Y_STARTLOC;
			
			addChild(playButton);
			addChild(menuButton);
			addChild(incrBetButton);
			addChild(decrBetButton);
			addChild(achievButton);
			addChild(viewPayoutButton);
			addChild(currentBetText);
			addChild(totalMoneyText);
			
			if(mainRef.DEBUG_MODE) addChild(gameRef.GetSS());	//to display stats while testing
			
			super.InitImage();
		}
		
		//PlayBtnInputMouseClick()
		//called on play button mouse click
		protected function PlayBtnInputMouseClick():void
		{
			mainRef.PlayRound(this);
		}
		//MenuBtnInputMouseClick()
		//called on back menu button mouse click
		protected function MenuBtnInputMouseClick():void
		{
			mainRef.ReturnToStartMenu(this);
		}
		//IncBetBtnInputMouseClick()
		//called on increase bet menu button mouse click
		protected function IncBetBtnInputMouseClick():void
		{
			gameRef.IncreaseBetSize();
			gameRef.RefreshSessionText();
			currentBetText.text = gameRef.GetSS().GetCurrentBetSize().toString();
		}
		//DecBetBtnInputMouseClick()
		//called on decrease bet button mouse click
		protected function DecBetBtnInputMouseClick():void
		{
			gameRef.DecreaseBetSize();
			gameRef.RefreshSessionText();
			currentBetText.text = gameRef.GetSS().GetCurrentBetSize().toString();
		}
		//AchievBtnInputMouseClick()
		//called on back menu button mouse click
		protected function AchievBtnInputMouseClick():void
		{
			mainRef.DisplayAchievMenu(this);
		}
		//ViewPayoutBtnInputMouseClick()
		//mouseclick will pop up payout display
		protected function ViewPayoutBtnInputMouseClick():void
		{
			addChild(payoutDisplay);
		}
		//PayoutDisplayInputMouseClick()
		//mouseclick will remove the payout display
		protected function PayoutDisplayInputMouseClick():void
		{
			removeChild(payoutDisplay);
		}
		
	}

}